package values.skill
{
	import core.manager.battle.BattleCountManager;
	import core.manager.battle.BattleEffectManager;
	
	import values.avatar.IPropertyProvider;
	import values.common.IAvatarProperty;

	
	
	/**
	 * 用特定公式计算最后数值的额外效果 
	 * @author azhang
	 * 
	 */	
	public class AddHpAdditinalEffectValue extends AdditionalEffectValue
	{
		public static const ADD_HP_ONE:String = "add_hp_one";
		
		public function AddHpAdditinalEffectValue()
		{
			super();
		}
		
		override public function effect():void
		{
			var tempateV:AdditionalEffectTemplateValue = _skillValue.template.additional;
			//////////////////////////几率没达到///////////////////////////////
			if(!BattleCountManager.countRandom(_skillValue.getLevelValueByTag(tempateV.basePossiblity))) return;
			/////////////////////////被抵抗了/////////////////////////////////
			if(tempateV.canResist && !_skillValue.checkSkillHasLogic(LogicEffectValue.IGNORE_RESIST) && BattleCountManager.countRandom(BattleCountManager.countResistRate(_owner , _hitter))) return;
			
			var effectObj:Object = {};
			var num:Number;
			for each(var proV:AdditionalProTemplateValue in tempateV.proDic)
			{
				if(_hitter[proV.proName] != null)
				{
					if(!proV.isSpecial())
					{
						if(proV.needBaseNum)
						{
							num = _baseDamageNum * _skillValue.getLevelValueByTag(proV.baseNum) / 100;
							_hitter[proV.proName] -= num;
						}
						else
						{
							num = SkillNumTypeKey.getResult(proV.numType , _hitter[proV.proName] , _skillValue.getLevelValueByTag(proV.baseNum));
							_hitter[proV.proName] -= num;
						}
					}
					else
					{
						num = getSpecialValue(proV);
						_hitter[proV.proName] -= num;
					}
					
					BattleEffectManager.showEffectValue(_owner , _hitter , {num:num , proName:proV.proName});
				}
			}
		}
		
		protected function getSpecialValue(proV:AdditionalProTemplateValue):Number
		{
			switch(proV.special)
			{
				case ADD_HP_ONE:
					return _skillValue.getLevelValueByTag(proV.params.a) + 
					( (_owner as IPropertyProvider).elementDamage + (_owner as IPropertyProvider).skillDamage  ) * 
					_skillValue.getLevelValueByTag(proV.params.b) / 1000;
					break;
			}
			
			return 0;
		}
	}
}